package com.tbit.uqbike.client.pojo.vo;


import com.tbit.uqbike.client.constant.ResponseCode;

/**
 * Json响应
 *
 * @author Leon
 * 2019年1月23日 下午3:49:22
 */
public class JsonResult {
    /**
     * 柱状图销售数
     */
    public Integer[] totals;
    /**
     * 柱状图横轴
     */
    public String[] times;
    /**
     * 销售金额
     */
    public Integer[] moneys;
    /**
     * 结果
     */
    private Integer ret;
    /**
     * 错误代码
     */
    private String code;
    /**
     * 错误消息
     */
    private String msg;
    /**
     * 结果
     */
    private Object data;
    /**
     * traceId
     */
    private String traceId;
    // 总数
    private Long total;

    private JsonResult(Integer ret) {
        this.ret = ret;
    }

    public JsonResult(Integer ret, Object data, Long total) {
        this.ret = ret;
        this.data = data;
        this.total = total;
    }

    private JsonResult(Object data, Integer ret) {
        this.data = data;
        this.ret = ret;
    }

    private JsonResult(Integer ret, String code, String msg, String traceId) {
        this.msg = msg;
        this.code = code;
        this.ret = ret;
        this.traceId = traceId;
    }

    public JsonResult(Integer ret, String code, String msg, Object data, String traceId) {
        super();
        this.ret = ret;
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.traceId = traceId;
    }

    public JsonResult(Integer ret, Integer[] totals, String[] times, Integer[] moneys) {
        this.ret = ret;
        this.totals = totals;
        this.times = times;
        this.moneys = moneys;
    }

    /**
     * 成功，有数据
     *
     * @param data
     * @return
     */
    public static JsonResult succ(Object data) {
        return new JsonResult(data, ResponseCode.SUCC);
    }

    public static JsonResult succ(Object data, Long total) {
        return new JsonResult(ResponseCode.SUCC, data, total);
    }

    /**
     * 成功，无数据
     *
     * @return
     */
    public static JsonResult succ() {
        return new JsonResult(ResponseCode.SUCC);
    }

    /**
     * 失败
     *
     * @param msg
     * @param code
     * @return
     */
    public static JsonResult fail(String code, String msg, String traceId) {
        return new JsonResult(ResponseCode.FAIL, code, msg, traceId);
    }

    /**
     * 失败
     *
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static JsonResult fail(String code, String msg, Object data, String traceId) {
        return new JsonResult(ResponseCode.FAIL, code, msg, data, traceId);
    }

    /**
     * 匹配柱状图结果
     *
     * @param totals
     * @param times
     * @param moneys
     * @return
     */
    public static JsonResult succ(Integer[] totals, String[] times, Integer[] moneys) {
        return new JsonResult(ResponseCode.SUCC, totals, times, moneys);
    }

    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }
}
